
// import * as Cesium from 'cesium';
// import 'cesium/Build/Cesium/Widgets/widgets.css';
declare var CooGL: any;

const initMapSource = () => {
  let viewer = new CooGL.MapViewer("map", {
    // 影像数据（在线数据）
    imageryProvider: new CooGL.WebMapTileServiceImageryProvider({
      url:
        "http://t0.tianditu.com/vec_w/wmts?service=wmts&request=GetTile&version=1.0.0&LAYER=vec&tileMatrixSet=w&TileMatrix={TileMatrix}&TileRow={TileRow}&TileCol={TileCol}&style=default&format=tiles&tk=014caf52420d202b243879e39eb36740",
      layer: "tdtBasicLayer",
      style: "default",
      format: "tiles",
      tileMatrixSetID: "GoogleMapsCompatible",
      show: true,
      maximumLevel: 14,
    }),
  });
  viewer.clockViewModel.currentTime = CooGL.JulianDate.fromIso8601(
    "2020-09-07T12:17:13"
  );
  viewer.extend(CooGL.CustomTilesetShaderMixin);

  let scene = viewer.scene;
  viewer.scene.globe.material = CooGL.Material.fromType("FanSe");
  // $viewer = viewer;
  // $scene = scene;
  // $camera = viewer.camera;
  // window.$viewer = viewer;
  // window.$scene = scene;
  // window.$camera = viewer.camera;
  //////////////////////////////////////// 场景配置START ////////////////////////////////////////
  let setting = { // 配置参数
    hdr: false,
    fxaa: true,
    light_intensity: 3,
    light_color: [255, 255, 255, 1.],
    bloom_enable: true,
    bloom_glowOnly: false,
    bloom_brightness: -0.29,
    bloom_contrast: 255,
    bloom_delta: 1.1300000000000001,
    bloom_sigma: 1.87,
    bloom_stepSize: 1.46,
    ao_enable: false,
    ao_ambientOcclusionOnly: false,
    ao_intensity: 3,
    ao_bias: 0.1,
    ao_lengthCap: 0.03,
    ao_stepSize: 1,
    ao_blurStepSize: 0.86,
    label_offset_x: 41,
    label_offset_y: 66,
    debugShowFramesPerSecond: false
  };

  // var gui = new dat.GUI();
  // var postProcessFolder = gui.addFolder("后处理");
  //
  // var bloomFolder = postProcessFolder.addFolder("泛光");
  // bloomFolder.add(setting, "bloom_glowOnly").onChange(function () {bloom.uniforms.glowOnly = setting.bloom_glowOnly;});
  // bloomFolder.add(setting, "bloom_enable").onChange(function () {bloom.enabled = setting.bloom_enable;});
  // bloomFolder.add(setting, "bloom_contrast").min(0).max(255).step(0.1).onChange(function () {bloom.uniforms.contrast = setting.bloom_contrast;});
  // bloomFolder.add(setting, "bloom_brightness").min(-2).max(2).step(0.01).onChange(function () {bloom.uniforms.brightness = setting.bloom_brightness;});
  //
  // bloomFolder.add(setting, "bloom_delta").min(-2).max(2).step(0.01).onChange(function () {bloom.uniforms.delta = setting.bloom_delta;});
  // bloomFolder.add(setting, "bloom_sigma").min(-2).max(2).step(0.01).onChange(function () {bloom.uniforms.sigma = setting.bloom_sigma;});
  // bloomFolder.add(setting, "bloom_stepSize").min(-2).max(2).step(0.01).onChange(function () {bloom.uniforms.stepSize = setting.bloom_stepSize;});
  // window.setting = setting;

  // 打开全局的鼠标点击事件
  viewer.globalScreenSpaceInputListener({
    enableLeftClick: true
  });

  viewer._cesiumWidget._creditContainer.style.display = 'none';

  scene.debugShowFramesPerSecond = setting.debugShowFramesPerSecond; // 产品上线后请注释这段

  viewer.scene.postProcessStages.fxaa.enabled = setting.fxaa; // 抗锯齿
  // scene.globe.depthTestAgainstTerrain = setting.depthTestAgainstTerrain; // 地形深度测试

  // // 设置光源 （默认太阳光）
  let sunlight = scene.light;
  // sunlight.color = CooGL.Color.fromBytes(
  //     setting.light_color[0],
  //     setting.light_color[1],
  //     setting.light_color[2],
  //     setting.light_color[3]
  // );
  sunlight.intensity = setting.light_intensity; // 光线强度

  // hdr
  scene.highDynamicRange = setting.hdr;

  // // 后置处理
  let postProcessStages = scene.postProcessStages;

  // 开启泛光
  let bloom = postProcessStages.bloom;
  bloom.enabled = setting.bloom_enable;
  bloom.uniforms.contrast = setting.bloom_contrast;
  bloom.uniforms.brightness = setting.bloom_brightness;
  bloom.uniforms.glowOnly = setting.bloom_glowOnly;

  bloom.uniforms.delta = setting.bloom_delta;
  bloom.uniforms.sigma = setting.bloom_sigma;
  bloom.uniforms.stepSize = setting.bloom_stepSize;
  // ao
  let ambientOcclusion = postProcessStages.ambientOcclusion;
  ambientOcclusion.enabled = setting.ao_enable;
  ambientOcclusion.uniforms.ambientOcclusionOnly = setting.ao_ambientOcclusionOnly;
  ambientOcclusion.uniforms.intensity = setting.ao_intensity;
  ambientOcclusion.uniforms.bias = setting.ao_bias;
  ambientOcclusion.uniforms.lengthCap = setting.ao_lengthCap;
  ambientOcclusion.uniforms.stepSize = setting.ao_stepSize;
  ambientOcclusion.uniforms.blurStepSize = setting.ao_blurStepSize;

  //////////////////////////////////////// 场景配置END ////////////////////////////////////////

}

export default initMapSource